package gossip.v2.message;

import com.baidu.bjf.remoting.protobuf.annotation.ProtobufClass;
import gossip.v2.cluster.ClusterManager;
import gossip.v2.cluster.GossipNode;
import lombok.Getter;


@Getter
@ProtobufClass
public abstract class GossipMessage {
    public enum Type {
        HEARTBEAT, SYNC, ACK, USER, HANDSHAKE, INDIRECT_CHECK, LEAVE, NODE_LIST
    }

    protected Type type;
    protected GossipNode sender;
    protected String senderId;

    public void resolveSender(ClusterManager clusterManager) {
        if (sender == null && senderId != null) {
            sender = clusterManager.getNodeById(senderId);
        }
    }
}
